package com.xgpro.pc.rolemanage.controller;

import com.xgpro.common.controller.BaseController;
import com.xgpro.common.dingtalk.service.contact.DDUserService;
import com.xgpro.common.results.PageResult;
import com.xgpro.common.results.ResponseResult;
import com.xgpro.domain.rolemanage.entity.Department;
import com.xgpro.domain.rolemanage.entity.Permissions;
import com.xgpro.domain.rolemanage.entity.ProfileEntity;
import com.xgpro.domain.rolemanage.entity.Role;
import com.xgpro.pc.rolemanage.service.DepartmentService;
import com.xgpro.pc.rolemanage.service.PermissionsService;
import com.xgpro.pc.rolemanage.service.RoleService;
import com.xgpro.pc.rolemanage.service.UserService;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import com.xgpro.domain.talentintroduction.entity.User;

import javax.annotation.Resource;
import java.util.*;

/**
 * @program: xg_dev
 * @description: 用户管理controller
 * @author: likai
 * @create: 2019-10-07 17:39
 **/
@CrossOrigin(allowCredentials = "true")
@RestController
public class UserController extends BaseController {

    @Resource
    private UserService userService;

    /**
     * 更新用户
     *
     * @param user
     * @throws Exception
     */
    @PutMapping(value = "user/{userId}")
    public ResponseResult<User> updateUser(@PathVariable Integer userId, @RequestBody User user) throws Exception {
        user.setId(userId);
        userService.updateUser(user);
        return ResponseResult.ok();
    }

    /**
     * 获取用户列表
     *
     * @param page
     * @param size
     * @param map
     * @return
     */
    @GetMapping(value = "user")
    public ResponseResult list(@RequestParam int page, @RequestParam int size, @RequestParam(required = false) Map map) {
        PageResult pageResult = userService.listUser(page, size, map);
        return ResponseResult.ok(pageResult);
    }

    /**
     * 获取用户详情
     *
     * @param userId
     * @return
     */
    @GetMapping(value = "user/{userId}")
    public ResponseResult getUser(@PathVariable Integer userId) {

        User user = userService.getUserInfoByUserId(userId);

        return ResponseResult.ok(user);

    }

    @DeleteMapping(value = "user/{userId}")
    public ResponseResult delete(@PathVariable Integer userId) {

        userService.deleteUserInfo(userId);

        return ResponseResult.ok();

    }

    @PostMapping(value = "user")
    public ResponseResult addUser(@RequestBody User user) {
        userService.addUser(user);
        return ResponseResult.ok();
    }

    /**
     * 维护用户角色信息
     *
     * @param param
     * @return
     */
    @PutMapping("assignRole")
    public ResponseResult assignRole(@RequestBody Map<String, Object> param) {
        userService.assignRole(param);

        return ResponseResult.ok();


    }

    @PutMapping(value = "update_user_detail")
    public ResponseResult updateUserDetail(@RequestBody Map<String, Object> param) {

        userService.updateUserDetail(param);

        return ResponseResult.ok();
    }

    @PutMapping(value = "updateTeaRalation")
    public ResponseResult updateTeaRalation(@RequestBody Map<String, Object> param) {
        userService.updateTeaRalation(param);


        return ResponseResult.ok();

    }

    @GetMapping(value = "tea_relation_status")
    public ResponseResult getStatus(Integer userId) {
        return ResponseResult.ok(userService.getStatus(userId));
    }

}
